using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.VisualStudio.Package;
using Microsoft.WowAddonStudio.Lua.Model;
using Microsoft.WowAddonStudio.Lua.Support;

using Microsoft.WowAddonStudio.Lua.LanguageService.Intellisense;

namespace Microsoft.WowAddonStudio.Lua.LanguageService.Model
{
    public class LuaMethods : Methods
    {
        private readonly IList<Function> functions;

        /// <summary>
        /// Initializes a new instance of the <see cref="LuaMethods"/> class.
        /// </summary>
        public LuaMethods()
        {
            this.functions = new List<Function>();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="LuaMethods"/> class.
        /// </summary>
        /// <param name="functions">The functions.</param>
        public LuaMethods(IEnumerable<Function> functions)
        {
            if (functions == null)
                throw new ArgumentNullException("functions");

            this.functions = new List<Function>(functions);
        }

        /// <summary>
        /// When implemented in a derived class, gets the number of overloaded method signatures represented in this collection.
        /// </summary>
        /// <returns>
        /// The number of signatures in the collection.
        /// </returns>
        public override int GetCount()
        {
            return functions.Count;
        }

        /// <summary>
        /// When implemented in a derived class, gets the name of the specified method signature.
        /// </summary>
        /// <param name="index">[in] The index of the method whose name is to be returned.</param>
        /// <returns>
        /// The name of the specified method, or null.
        /// </returns>
        public override string GetName(int index)
        {
            return functions[index].GetName();
        }
        /// <summary>
        /// When implemented in a derived class, gets the description of the specified method signature.
        /// </summary>
        /// <param name="index">[in] An index into the internal list to the desired method signature.</param>
        /// <returns>
        /// The description of the specified method signature, or null if the method signature does not exist.
        /// </returns>
        public override string GetDescription(int index)
        {
            return functions[index].GetMethodDescription();
        }

        /// <summary>
        /// When implemented in a derived class, gets the return type of the specified method signature.
        /// </summary>
        /// <param name="index">[in] An index into the list of method signatures.</param>
        /// <returns>
        /// The return type of the specified method signature, or null.
        /// </returns>
        public override string GetType(int index)
        {
            return functions[index].GetReturnType();
        }

        /// <summary>
        /// When implemented in a derived class, gets the number of parameters on the specified method signature.
        /// </summary>
        /// <param name="index">[in] An index into the list of method signatures.</param>
        /// <returns>
        /// The number of parameters on the specified method signature, or -1.
        /// </returns>
        public override int GetParameterCount(int index)
        {
            return functions[index].Parameters != null ? functions[index].Parameters.Length : 0;
        }

        /// <summary>
        /// Gets the parameter info.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <param name="parameterIndex">Index of the parameter.</param>
        /// <param name="name">The name.</param>
        /// <param name="display">The display.</param>
        /// <param name="description">The description.</param>
        public override void GetParameterInfo(int index, int parameterIndex, out string name, out string display, out string description)
        {
            var parameterInfo = functions[index].GetParameterInfo(functions[index].Parameters[parameterIndex]);

            name = parameterInfo.Name;
            display = parameterInfo.Display;
            description = parameterInfo.Description;
       }
    }
}